
FUNCTION FindValiDate RETURNS DATE (INPUT idate AS DATE,
                                    INPUT part AS CHARACTER ) FORWARD. 
DEFINE VAR part LIKE pc_part.
DEFINE VAR idate LIKE pc_start.
DEFINE VAR fdate LIKE pc_start.

part = "test".
idate = date("12/05/03").

fdate = FindValiDate (idate, part).

FOR EACH pc_mstr NO-LOCK WHERE pc_part = part BY pc_start:
  DISP pc_list pc_part pc_start pc_expire.
END.

FOR EACH pc_mstr WHERE pc_part = part 
                   AND pc_start = fdate:
    DISP pc_list pc_part pc_um pc_start pc_expire pc_min_qty[1] pc_amt[1].

END.
    

FUNCTION FindValiDate RETURNS DATE:

   FOR EACH pc_mstr NO-LOCK 
      WHERE pc_part = part 
        AND pc_start <= idate        
      BREAK BY pc_part BY pc_start DESC:

      ACCUMULATE pc_start (MAX BY pc_part).
   END.

   RETURN (ACCUMULATE MAX pc_start).
END FUNCTION.
